<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Array compare condition | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'condition-array-compare.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/condition-array-compare.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/condition-array-compare.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/condition-array-compare.html" rel="nofollow" target="_blank">../en/condition-array-compare.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="xpack-alerting.html">Alerting on cluster and index events</a></span>
»
<span class="breadcrumb-link"><a href="condition.html">Conditions</a></span>
»
<span class="breadcrumb-node">Array compare condition</span>
</div>
<div class="navheader">
<span class="prev">
<a href="condition-compare.html">« Compare condition</a>
</span>
<span class="next">
<a href="condition-script.html">Script condition »</a>
</span>
</div>
<div class="section xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="condition-array-compare"></a>Array compare condition<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/watcher/condition/array-compare.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>
<p>Use <code class="literal">array_compare</code> to compare an array of values in the execution context to a
given value. See <a class="xref" href="condition-compare.html#condition-compare-operators" title="Supported comparison operators">Table 87, “Supported comparison operators”</a>
for the operators you can use.</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_using_an_array_compare_condition"></a>Using an array compare condition<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/watcher/condition/array-compare.asciidoc">edit</a>
</h3>
</div></div></div>
<p>To use the <code class="literal">array_compare</code> condition, you specify the array in the execution
context that you want to evaluate, a
<a class="xref" href="condition-compare.html#condition-compare-operators" title="Supported comparison operators">comparison operator</a>, and the value you want to
compare against. Optionally, you can specify the path to the field in each array
element that you want to evaluate.</p>
<p>For example, the following <code class="literal">array_compare</code> condition returns <code class="literal">true</code> if there
is at least one bucket in the aggregation that has a <code class="literal">doc_count</code> greater
than or equal to 25:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
  "condition": {
    "array_compare": {
      "ctx.payload.aggregations.top_tweeters.buckets" : { <a id="CO512-1"></a><i class="conum" data-value="1"></i>
        "path": "doc_count", <a id="CO512-2"></a><i class="conum" data-value="2"></i>
        "gte": { <a id="CO512-3"></a><i class="conum" data-value="3"></i>
          "value": 25 <a id="CO512-4"></a><i class="conum" data-value="4"></i>
        }
      }
    }
  }
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO512-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The path to the array in the execution
context that you want to evaluate, specified in dot notation.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO512-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>The path to the field in each array element that you want to evaluate.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO512-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>The <a class="xref" href="condition-compare.html#condition-compare-operators" title="Supported comparison operators">comparison operator</a> to use.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO512-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>The comparison value. Supports date math like the
<a class="xref" href="condition-compare.html#compare-condition-date-math">compare condition</a>.</p>
</td>
</tr>
</table>
</div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>When using fieldnames that contain a dot this condition will not
work, use a <a class="xref" href="condition-script.html" title="Script condition">script condition</a> instead.</p>
</div>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_array_compare_condition_attributes"></a>Array-compare condition attributes<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/x-pack/docs/en/watcher/condition/array-compare.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="informaltable">
<table border="1" cellpadding="4px">
<colgroup>
<col class="col_1">
<col class="col_2">
</colgroup>
<thead>
<tr>
<th align="left" valign="top">Name</th>
<th align="left" valign="top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left" valign="top"><p><code class="literal">&lt;array path&gt;</code></p></td>
<td align="left" valign="top"><p>The path to the array in the execution
                                         context, specified in dot notation.
                                         For example, <code class="literal">ctx.payload.aggregations.top_tweeters.buckets</code>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">&lt;array path&gt;.path</code></p></td>
<td align="left" valign="top"><p>The path to the field in each array element
                                         that you want to evaluate. For example,
                                         <code class="literal">doc_count</code>. Defaults to an empty string.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">&lt;array path&gt;.&lt;operator&gt;.quantifier</code></p></td>
<td align="left" valign="top"><p>How many matches are required for the
                                         comparison to evaluate to <code class="literal">true</code>: <code class="literal">some</code>
                                         or <code class="literal">all</code>. Defaults to <code class="literal">some</code>--there must
                                         be at least one match. If the array is
                                         empty, the comparison evaluates to <code class="literal">true</code>
                                         if the quantifier is set to <code class="literal">all</code> and
                                         <code class="literal">false</code> if the quantifier is set to
                                         <code class="literal">some</code>.</p></td>
</tr>
<tr>
<td align="left" valign="top"><p><code class="literal">&lt;array path&gt;.&lt;operator&gt;.value</code></p></td>
<td align="left" valign="top"><p>The value to compare against.</p></td>
</tr>
</tbody>
</table>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="condition-compare.html">« Compare condition</a>
</span>
<span class="next">
<a href="condition-script.html">Script condition »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>